package com.dxf.bigdata.D05_spark_again.工程化代码.common

import com.dxf.bigdata.D05_spark_again.工程化代码.utils.EnvUtils
import org.apache.spark.{SparkConf, SparkContext}

trait TApplicationEnv {


  def start(master:String ="local[*]", appName:String = "app")(op: => Unit): Unit = {
    val sparkConf = new SparkConf().setMaster(master).setAppName(appName)
    sparkConf.set("spark.port.maxRetries", "100")
    val sc = new SparkContext(sparkConf)
    EnvUtils.put(sc)
    try {
      op
    } catch {
      case ex => println(ex.getMessage)
    }
    EnvUtils.clear()
    sc.stop()
  }


}
